{% block component_form_select_birthday %}

    {% set birthday = false %}
    {% set birthmonth = false %}
    {% set birthyear = false %}

    {% if data.has('birthdayDay') === true and data.get('birthdayDay') is not empty %}
        {# Registration Form #}
        {% if data.get('birthdayDay') is not empty %}
            {% set birthday = data.get('birthdayDay') %}
        {% endif %}

        {% if data.get('birthdayMonth') is not empty %}
            {% set birthmonth = data.get('birthdayMonth') %}
        {% endif %}

        {% if data.get('birthdayYear') is not empty %}
            {% set birthyear = data.get('birthdayYear') %}
        {% endif %}
    {% elseif data.birthday %}
        {# Profile Page #}
        {% set birthday = data.birthday|date('d', false) %}
        {% set birthmonth = data.birthday|date('m', false) %}
        {% set birthyear = data.birthday|date('Y', false) %}
    {% endif %}

    <div class="form-group{% if additionalClass is not empty %} {{ additionalClass }}{% endif %}">
        {% block component_form_select_birthday_label %}
            {% if label %}
                <label class="form-label" for="{{ idPrefix ~ prefix }}-personalBirthday">
                    {{ label }}

                    {% if 'required' in validationRules %}
                        <span class="form-required-label" aria-hidden="true">{{ 'general.required'|trans|sw_sanitize }}</span>
                    {% endif %}
                </label>
            {% endif %}
        {% endblock %}

        <div class="row g-2">
            {% block component_form_select_birthday_day %}
                <div class="col-4">
                    {% block component_form_select_birthday_day_select %}
                        <select class="form-select{% if formViolations.getViolations('/birthdayDay') is not empty %} is-invalid{% endif %}"
                                id="{{ idPrefix ~ prefix }}personalBirthday"
                                name="{% if prefix %}{{ prefix }}[birthdayDay]{% else %}birthdayDay{% endif %}"
                                aria-describedby="{{ idPrefix ~ prefix }}-personalBirthday-feedback"
                                {% if validationRules is not empty %}data-validation="{{ validationRules }}"{% endif %}
                                {% if 'required' in validationRules %}aria-required="true"{% endif %}>
                            {% block component_form_select_birthday_day_select_options %}
                                {% if not birthday %}
                                    <option selected="selected" value="">
                                        {{ 'account.personalBirthdaySelectDay'|trans|sw_sanitize }}
                                    </option>
                                {% endif %}
                                {% for day in range(1, 31) %}
                                    <option value="{{ day }}"
                                        {% if day == birthday %} selected="selected"{% endif %}>
                                        {{ day }}
                                    </option>
                                {% endfor %}
                            {% endblock %}
                        </select>
                    {% endblock %}

                    {% block component_form_select_birthday_day_feedback %}
                        <div id="{{ idPrefix ~ prefix }}personalBirthday-feedback"
                             class="form-field-feedback">
                            {% block component_form_select_birthday_day_feedback_violations %}
                                {% if formViolations.getViolations('/birthdayDay') is not empty %}
                                    {% sw_include '@Storefront/storefront/utilities/form-violation.html.twig' with {
                                        violationPath: '/birthdayDay'
                                    } %}
                                {% endif %}
                            {% endblock %}
                        </div>
                    {% endblock %}
                </div>
            {% endblock %}

            {% block component_form_select_birthday_month %}
                <div class="col-4">
                    {% block component_form_select_birthday_month_select %}
                        <select class="form-select{% if formViolations.getViolations('/birthdayMonth') is not empty %} is-invalid{% endif %}"
                                id="{{ idPrefix ~ prefix }}personalBirthdayMonth"
                                name="{% if prefix %}{{ prefix }}[birthdayMonth]{% else %}birthdayMonth{% endif %}"
                                aria-describedby="{{ idPrefix ~ prefix }}-personalBirthdayMonth-feedback"
                                {% if validationRules is not empty %}data-validation="{{ validationRules }}"{% endif %}
                                {% if 'required' in validationRules %}aria-required="true"{% endif %}>
                            {% block component_form_select_birthday_month_select_options %}
                                {% if not birthmonth %}
                                    <option selected="selected"
                                            value="">
                                        {{ 'account.personalBirthdaySelectMonth'|trans|sw_sanitize }}
                                    </option>
                                {% endif %}
                                {% for month in range(1, 12) %}
                                    <option value="{{ month }}"
                                        {% if month == birthmonth %} selected="selected"{% endif %}>
                                        {{ month }}
                                    </option>
                                {% endfor %}
                            {% endblock %}
                        </select>
                    {% endblock %}

                    {% block component_form_select_birthday_month_feedback %}
                        <div id="{{ idPrefix ~ prefix }}personalBirthdayMonth-feedback"
                             class="form-field-feedback">
                            {% block component_form_select_birthday_month_feedback_violations %}
                                {% if formViolations.getViolations('/birthdayMonth') is not empty %}
                                    {% sw_include '@Storefront/storefront/utilities/form-violation.html.twig' with {
                                        violationPath: '/birthdayMonth'
                                    } %}
                                {% endif %}
                            {% endblock %}
                        </div>
                    {% endblock %}
                </div>
            {% endblock %}

            {% block component_form_select_birthday_year %}
                <div class="col-4">
                    {% block component_form_select_birthday_year_select %}
                        {% set currentYear = 'now'|date('Y') %}
                        {% set startYear = currentYear - 120 %}

                        <select class="form-select{% if formViolations.getViolations('/birthdayYear') is not empty %} is-invalid{% endif %}"
                                id="{{ idPrefix ~ prefix }}personalBirthdayYear"
                                name="{% if prefix %}{{ prefix }}[birthdayYear]{% else %}birthdayYear{% endif %}"
                                aria-describedby="{{ idPrefix ~ prefix }}-personalBirthdayYear-feedback"
                                {% if validationRules is not empty %}data-validation="{{ validationRules }}"{% endif %}
                                {% if 'required' in validationRules %}aria-required="true"{% endif %}>
                            {% block component_form_select_birthday_year_select_options %}
                                {% if not birthyear %}
                                    <option selected="selected"
                                            value="">
                                        {{ 'account.personalBirthdaySelectYear'|trans|sw_sanitize }}
                                    </option>
                                {% endif %}
                                {% for year in range(currentYear, startYear) %}
                                    <option value="{{ year }}"
                                        {% if year == birthyear %} selected="selected"{% endif %}>
                                        {{ year }}
                                    </option>
                                {% endfor %}
                            {% endblock %}
                        </select>
                    {% endblock %}

                    {% block component_form_select_birthday_year_feedback %}
                        <div id="{{ idPrefix ~ prefix }}personalBirthdayYear-feedback"
                             class="form-field-feedback">
                            {% block component_form_select_birthday_year_feedback_violations %}
                                {% if formViolations.getViolations('/birthdayYear') is not empty %}
                                    {% sw_include '@Storefront/storefront/utilities/form-violation.html.twig' with {
                                        violationPath: '/birthdayYear'
                                    } %}
                                {% endif %}
                            {% endblock %}
                        </div>
                    {% endblock %}
                </div>
            {% endblock %}
        </div>
    </div>
{% endblock %}
